package com.young.mhl.service;

import com.young.mhl.dao.DiningTableDAO;
import com.young.mhl.domain.DiningTable;

import java.util.List;

/**
 * @Author: young
 * @Date: 2021-12-04 15:37
 * @Description:
 */
public class DiningTableService {
	// 定义一个DiningTableDAO对象
	private DiningTableDAO diningTableDAO = new DiningTableDAO();
	
	// 返回所有餐桌信息
	public List<DiningTable> list(){
		List<DiningTable> diningTables = diningTableDAO.queryMany("select id,state from diningTable", DiningTable.class);
		return diningTables;
	}
	
	// 根据id查询对应的餐桌
	// 如果返回null，表示对应餐桌不存在
	public DiningTable getDiningTableById(int id){
		return diningTableDAO.querySingle("select * from diningTable where id=?",DiningTable.class,id);
	}
	
	//如果餐桌可以预定，对其状态进行更新
	public boolean orderDiningTable(int id,String orderName,String orderTel){
		int update = diningTableDAO.update("update diningTable set state = '已预定',orderName=?,OrderTel=? where id=?", orderName, orderTel, id);
		return update >0;
	}
	
	//更新餐桌状态
	public boolean updateDiningTableState(int id,String state){
		int update = diningTableDAO.update("update diningTable set state=? where id=?", state, id);
		return update > 0;
	}
	
	//将指定的餐桌设置为空闲状态
	public boolean updateDiningTableStateToFree(int id,String state){
		int update = diningTableDAO.update("update diningTable set state=?,orderName='',orderTel='' where id=?", state, id);
		return update > 0;
	}
}
